<?
$page_title="Reports ";
$mindex=1;
?>
<?include("includes/header.php") ?>
<div class="bodycontent">
<script src="http://tablesorter.com/jquery.tablesorter.min.js"  type="text/javascript" ></script>
<form method="post" >
<div class="frmrow">
	<b>Date - From :</b>
	<input type="text" name="timesheet_fdate" style="width:77px;" id="timesheet_fdate" value="<?=date('d-m-Y',time())?>"/>
	<b>To  :</b><input type="text" style="width:77px;" name="timesheet_tdate" id="timesheet_tdate" value="<?=date('d-m-Y',time())?>"/>
	<b>Contains Keywords :</b><input type="text" name="keyword" id="keyword" />
	<?
	$userlist=qry_data("select user_id,user_name from dev_user_mast"); 
	?>
	<select class="selectbox" name="user_id">
	<option value="">---All Users---</option>
	<?foreach($userlist as $k=>$userinfo){?>
	<option value="<?=$userinfo["user_id"]?>"><?=$userinfo["user_name"]?></option>
	
	<?}?>
	
	</select>
	<input type="submit" value="Submit" class="button" />
	 <br/>
	 <hr/>
</div>
</form>

<?

if($_POST) {
$baseQry="select t.*,u.user_name from dev_user_timesheet t left join dev_user_mast u on t.user_id=u.user_id ";
$keyword=$_POST["keyword"];
$fdt=$_POST["timesheet_fdate"];
$tdt=$_POST["timesheet_tdate"];
$fdt=getValidDateFormat($fdt);
$tdt=getValidDateFormat($tdt);
$userid=$_POST["user_id"];

$where="where 1=1 and t.timesheet_date between  '#timesheet_fdate#' and '#timesheet_tdate#' ";
if($keyword!="") $where=$where." and (t.comments like '%#keyword#%' or t.tag like '%#keyword#%')";
if((int)$userid>0) $where=$where." and t.user_id=".$userid;

$where=str_replace("#timesheet_fdate#",$fdt,$where);
$where=str_replace("#timesheet_tdate#",$tdt,$where);
$where=str_replace("#keyword#",$keyword,$where);

$where=str_replace("#keyword#",$keyword,$where);
//echo $baseQry.$where;
$sheetInfo=qry_data($baseQry.$where);

?>
<table id="timesheetList" class="tablesorter"> 
	<thead> 
	<tr> 
	    <th>S.No</th> 
	    <th>Name</th> 
	    <th>Sheet Date</th> 
	    <th>Added Date</th> 
	    <th>Tag</th> 
	   <th>Comments</th> 
	</tr> 
	</thead> 
	<tbody> 
	<? foreach($sheetInfo as $k=>$entry) {?>
	<tr> 
	<td><?=$k+1?></td>
	<td><?=$entry["user_name"]?></td> 
	<td><?=$entry["timesheet_date"]?></td> 
	<td><?=$entry["rec_created"]?></td> 
	<td><?=$entry["tag"]?></td> 
	<td><?=$entry["comments"]?></td> 
	</tr> 
	<? } ?>
	
	</tbody> 
	</table> 
<? }?>

</div>

<script type="text/javascript">

$(document).ready(function(){ 
	
    	$( "#timesheet_fdate" ).datepicker({ dateFormat: 'dd-mm-yy' });
    	$( "#timesheet_tdate" ).datepicker({ dateFormat: 'dd-mm-yy' });
    	$("#ui-datepicker-div").hide();
    	
    	});
</script>

<?include("includes/footer.php") ?>